#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Croquette v1.0
# By Michael Lee and David Gomes
# Released August 1st, 2011
#
# Please see /readme_Croquette.txt
# Licensed under the MIT License (see /license_Croquette.txt)
#
# Written in Python 2.7
#

def _flip_dictionary(input_dict):
    """Takes in a dictionary and flips the keys and the values.

    Arguements:
     - input_dict: Ideally, the dictionary provided in this file.

    Returns:
     - A tuple: (new_dictionary, maximum_word_length)
    """
    new_dict = {}

    for (token, word) in input_dict.items():
        if type(word) == dict:
            (new_dict_2, temp) = _flip_dictionary(word)
            for w, t in new_dict_2.items():
                new_dict[w] = token + t
        elif type(word) == list:
            for i in word:
                new_dict[i] = (token)
        elif type(word) == str:
            new_dict[word] = token

    max_word_size = 0
    for (word, token) in new_dict.items():
        if len(word) > max_word_size:
            max_word_size = len(word)

    return (new_dict, max_word_size)

def _register_new(dictionary, *args):
    dictionary["".join(args)] = "".join([dictionary[token] for token in args])
    return
    

class Axe():
    def __init__(self):
        # The list indicates how much to increment (or decrement) the current
        # line, next line, and 3rd line away.
        self.specials = {"CE":[0,1,1],       # If
                         "D1":[0,1,1],       # While
                         "D2":[0,1,1],       # For
                         "D3":[0,1,1],       # Repeat
                         "DB":[0,1,1],       # DS>(
                         "2D":[0,1,1],       # !
                         "D4":[-1,-1,-1],    # End
                         "D0":[-1,0,0]}      # Else

        # If True, indentation is added immediately.
        self.end = {"3F":True,     # \n (newline)
                    "3E":False}    # :  (colon)
        
        self.singles = {'"'      : ['"', '\n'],
                        '['      : [']', '\n'],
                        '"appv'  : '"',
                        '"var'   : '"',
                        '"grp'   : '"',
                        '"pgrm'  : '"',
                        '.'      : '\n'}
        
        ### VERY IMPORTANT NOTE:
        ### All redundancy in the below dictionary is deliberate.
        ### The first item in any list is the output for ascii character mode.
        ### The last item in any list is the output for special characters mode.
        ### Any items in the middle are alternate token forms.
        ###
        ### If there is no special character forms for a token, but there are alternate
        ### forms, the first and last items should be the same.

        self.dictionary = {"00":"",
                   "01":[">Tok",
                         ">DMS",
                         "▶DMS",
                         "►DMS,",
                         "▶Tok",
                         "►Tok"],
                   "02":[">Dec",
                         "▶Dec",
                         "►Dec"],
                   "03":[">Char",
                         ">Frac",
                         "▶Frac",
                         "►Frac",
                         "▶Char",
                         "►Char"],
                   "04":["->",
                         "→"],
                   "05":"Boxplot",
                   "06":"[",
                   "07":"]",
                   "08":"{",
                   "09":"}",
                   "0A":"^^r",
                   "0B":["^^o",
                         "°"],
                   "0C":"^^-1",
                   "0D":"^^2",
                   "0E":["T^^",
                         "^^T",
                         "T^^"],
                   "0F":"^^3",
                   "10":"(",
                   "11":")",
                   "12":"round(",
                   "13":"pxl-Test(",
                   "14":"augment(",
                   "15":"rowSwap(",
                   "16":"row+(",
                   "17":"*row(",
                   "18":"*row+(",
                   "19":"max(",
                   "1A":"min(",
                   "1B":["R>Pr(",
                         "R▶Pr(",
                         "R►Pr("],
                   "1C":["R>Ptheta(",
                         "R▶Pθ(",
                         "R►Pθ("],
                   "1D":["P>Rx(",
                         "P▶Rx(",
                         "P►Rx("],
                   "1E":["P>Ry(",
                         "P▶Ry(",
                         "P►Ry("],
                   "1F":"median(",
                   "20":"randM(",
                   "21":"mean(",
                   "22":"solve(",
                   "23":"seq(",
                   "24":"fnInt(",
                   "25":"nDeriv(",
                   "27":"fMin(",
                   "28":"fMax(",
                   "29":" ",
                   "2A":"\"",
                   "2B":",",
                   "2C":"[i]",
                   "2D":"!",
                   "2E":"CubicReg ",
                   "2F":"QuartReg ",
                   "30":"0",
                   "31":"1",
                   "32":"2",
                   "33":"3",
                   "34":"4",
                   "35":"5",
                   "36":"6",
                   "37":"7",
                   "38":"8",
                   "39":"9",
                   "3A":".",
                   "3B":"|E",
                   "3C":" or ",
                   "3D":" xor ",
                   "3E":":",
                   "3F":"\n",
                   "40":" and ",
                   "41":"A",
                   "42":"B",
                   "43":"C",
                   "44":"D",
                   "45":"E",
                   "46":"F",
                   "47":"G",
                   "48":"H",
                   "49":"I",
                   "4A":"J",
                   "4B":"K",
                   "4C":"L",
                   "4D":"M",
                   "4E":"N",
                   "4F":"O",
                   "50":"P",
                   "51":"Q",
                   "52":"R",
                   "53":"S",
                   "54":"T",
                   "55":"U",
                   "56":"V",
                   "57":"W",
                   "58":"X",
                   "59":"Y",
                   "5A":"Z",
                   "5B":["theta",
                         "θ"],
                   "5C":{"00":"[A]",
                         "01":"[B]",
                         "02":"[C]",
                         "03":"[D]",
                         "04":"[E]",
                         "05":"[F]",
                         "06":"[G]",
                         "07":"[H]",
                         "08":"[I]",
                         "09":"[J]"},
                   "5D":{"00":"L1",
                         "01":"L2",
                         "02":"L3",
                         "03":"L4",
                         "04":"L5",
                         "05":"L6"},
                   "5E":{"10":"Y1",
                         "11":"Y2",
                         "12":"Y3",
                         "13":"Y4",
                         "14":"Y5",
                         "15":"Y6",
                         "16":"Y7",
                         "17":"Y8",
                         "18":"Y9",
                         "19":"Y0",
                         "20":"X1T",
                         "21":"Y1T",
                         "22":"X2T",
                         "23":"Y2T",
                         "24":"X3T",
                         "25":"Y3T",
                         "26":"X4T",
                         "27":"Y4T",
                         "28":"X5T",
                         "29":"Y5T",
                         "2A":"X6T",
                         "2B":"Y6T",
                         "40":"r1",
                         "41":"r2",
                         "42":"r3",
                         "43":"r4",
                         "44":"r5",
                         "45":"r6",
                         "80":"var",
                         "81":"appv",
                         "82":"grp"},
                   "5F":"prgm",
                   "60":{"00":"Pic1",
                         "01":"Pic2",
                         "02":"Pic3",
                         "03":"Pic4",
                         "04":"Pic5",
                         "05":"Pic6",
                         "06":"Pic7",
                         "07":"Pic8",
                         "08":"Pic9",
                         "09":"Pic0"},
                   "61":{"00":"GDB1",
                         "01":"GDB2",
                         "02":"GDB3",
                         "03":"GDB4",
                         "04":"GDB5",
                         "05":"GDB6",
                         "06":"GDB7",
                         "07":"GDB8",
                         "08":"GDB9",
                         "09":"GDB0"},
                   "62":{"01":"[RegEQ]",
                         "02":"[n]",
                         "03":"[xhat]",
                         "04":"[Sigmax]",
                         "05":"[Sigmax^2]",
                         "06":"[Sx]",
                         "07":"[sigmax]",
                         "08":"[minX]",
                         "09":"[maxX]",
                         "0A":"[minY]",
                         "0B":"[maxY]",
                         "0C":"[yhat]",
                         "0D":"[Sigmay]",
                         "0E":"[Sigmay^2]",
                         "0F":"[Sy]",
                         "10":"[sigmay]",
                         "11":"[Sigmaxy]",
                         "12":"[r]",
                         "13":"[Med]",
                         "14":"[Q1]",
                         "15":"[Q3]",
                         "16":"[a]",
                         "17":"[b]",
                         "18":"[c]",
                         "19":"[d]",
                         "1A":"[e]",
                         "1B":"[x1]",
                         "1C":"[x2]",
                         "1D":"[x3]",
                         "1E":"[y1]",
                         "1F":"[y2]",
                         "20":"[y3]",
                         "21":"[recursiven]",
                         "22":"[p]",
                         "23":"[z]",
                         "24":"[t]",
                         "25":"[chi^2]",
                         "26":"|F",
                         "27":"[df]",
                         "28":"[phat]",
                         "29":"[phat1]",
                         "2A":"[phat2]",
                         "2B":"[xhat1]",
                         "2C":"[Sx1]",
                         "2D":"[n1]",
                         "2E":"[xhat2]",
                         "2F":"[Sx2]",
                         "30":"[n2]",
                         "31":"[Sxp]",
                         "32":"[lower]",
                         "33":"[upper]",
                         "34":"[s]",
                         "35":"[r^2]",
                         "36":"[R^2]",
                         "37":"[factordf]",
                         "38":"[factorSS]",
                         "39":"[factorMS]",
                         "3A":"[errordf]",
                         "3B":"[errorSS]",
                         "3C":"[errorMS]"},
                   "63":{"00":"ZXscl",
                         "01":"ZYscl",
                         "02":"Xscl",
                         "03":"Yscl",
                         "04":"u(nMin)",
                         "05":"v(nMin)",
                         "06":"Un-1",
                         "07":"Vn-1",
                         "08":"Zu(nmin)",
                         "09":"Zv(nmin)",
                         "0A":"Xmin",
                         "0B":"Xmax",
                         "0C":"Ymin",
                         "0D":"Ymax",
                         "0E":"Tmin",
                         "0F":"Tmax",
                         "10":["thetaMin",
                               "θMin"],
                         "11":["thetaMax",
                               "θMax"],
                         "12":"ZXmin",
                         "13":"ZXmax",
                         "14":"ZYmin",
                         "15":"ZYmax",
                         "16":["Zthetamin",
                               "ZθMin"],
                         "17":["Zthetamax",
                               "Zθmax"],
                         "18":"ZTmin",
                         "19":"ZTmax",
                         "1A":"TblStart",
                         "1B":"PlotStart",
                         "1C":"ZPlotStart",
                         "1D":"nMax",
                         "1E":"ZnMax",
                         "1F":"nMin",
                         "20":"ZnMin",
                         "21":"DeltaTbl",
                         "22":"Tstep",
                         "23":["thetastep",
                               "θstep"],
                         "24":"ZTstep",
                         "25":["Zthetastep",
                               "Zθstep"],
                         
                         "26":"DeltaX",
                         "27":"DeltaY",
                         "28":"XFact",
                         "29":"YFact",
                         "2A":"TblInput",
                         "2B":"|N",
                         "2C":"I%",
                         "2D":"PV",
                         "2E":"PMT",
                         "2F":"FV",
                         "30":"P/Y",
                         "31":"C/Y",
                         "32":"w(nMin)",
                         "33":"Zw(nMin)",
                         "34":"PlotStep",
                         "35":"ZPlotStep",
                         "36":"Xres",
                         "37":"ZXres"},
                   "64":"Radian",
                   "65":"Degree",
                   "66":"Normal",
                   "67":"Sci",
                   "68":"Eng",
                   "69":"Float",
                   "6A":"=",
                   "6B":"<",
                   "6C":">",
                   "6D":["<=",
                         "=<",
                         "≤"],
                   "6E":["=>",
                         ">=",
                         "≥"],
                   "6F":["!=",
                         "=!",
                         "=/=",
                         "≠"],
                   "70":"+",
                   "71":"-",
                   "72":"Ans",
                   "73":"Fix ",
                   "74":"Horiz",
                   "75":"Full",
                   "76":"Func",
                   "77":"Param",
                   "78":"Polar",
                   "79":"Seq",
                   "7A":"IndpntAuto",
                   "7B":"IndpntAsk",
                   "7C":"DependAuto",
                   "7D":"DependAsk",
                   "7E":{"00":"Sequential",
                         "01":"Simul",
                         "02":"PolarGC",
                         "03":"RectGC",
                         "04":"CoordOn",
                         "05":"CoordOff",
                         "06":"Connected",
                         "07":"Dot",
                         "08":"AxesOn",
                         "09":"AxesOff",
                         "0A":"GridOn",
                         "0B":"GridOff",
                         "0C":"LabelOn",
                         "0D":"LabelOff",
                         "0E":"Web",
                         "0F":"Time",
                         "10":"uvAxes",
                         "11":"vwAxes",
                         "12":"uwAxes"},
                   "7F":[" plotxor ",
                         "plotzor",
                         "plotsquare"
                         " plotsquare "],    # □
                   "80":[" plotor ",
                         "plotor",
                         " plotcross ",
                         "plotcross",
                         " plotadd ",
                         "|+"],
                   "81":["plotand",
                         " plotdot "
                         "plotdot"
                         "plotand"],
                   "82":"*",
                   "83":["/",
                         "÷",
                         "/"],
                   "84":"Trace",
                   "85":"ClrDraw",
                   "86":"ZStandard",
                   "87":"ZTrig",
                   "88":"ZBox",
                   "89":"Zoom In",
                   "8A":"Zoom Out",
                   "8B":"ZSquare",
                   "8C":"ZInteger",
                   "8D":"ZPrevious",
                   "8E":"ZDecimal",
                   "8F":"ZoomStat",
                   "90":"ZoomRcl",
                   "91":"PrintScreen",
                   "92":"ZoomSto",
                   "93":"Text(",
                   "94":" nPr ",
                   "95":" nCr ",
                   "96":["FnOn ",
                         "FnOn",
                         "FnOn "],
                   "97":["FnOff ",
                         "FnOff",
                         "FnOff "],
                   "98":["StorePic ",
                         "StorePic",
                         "StorePic "],
                   "99":["RecallPic ",
                         "RecallPic",
                         "RecallPic "],
                   "9A":["StoreGDB ",
                         "StoreGDB",
                         "StoreGDB "],
                   "9B":["RecallGDB ",
                         "RecallGDB",
                         "RecallGDB "],
                   "9C":"Line(",
                   "9D":"Vertical ",
                   "9E":"Pt-On(",
                   "9F":"Pt-Off(",
                   "A0":"Pt-Change(",
                   "A1":"Pxl-On(",
                   "A2":"Pxl-Off(",
                   "A3":"Pxl-Change(",
                   "A4":"Shade(",
                   "A5":"Circle(",
                   "A6":"Horizontal ",
                   "A7":["Bitmap(",
                         "Tangent(",
                         "Bitmap"],
                   "A8":["DrawInv ",
                         "DrawInv",
                         "DrawInv "],
                   "A9":"Text ",
                   "AA":{"00":"Str1",
                         "01":"Str2",
                         "02":"Str3",
                         "03":"Str4",
                         "04":"Str5",
                         "05":"Str6",
                         "06":"Str7",
                         "07":"Str8",
                         "08":"Str9",
                         "09":"Str0"},
                   "AB":"rand",
                   "AC":["pi",
                         "π"],
                   "AD":"getKey",
                   "AE":"'",
                   "AF":"?",
                   "B0":"~",
                   "B1":["sign{",
                         "int(",
                         "sign{"],
                   "B2":"abs(",
                   "B3":["Zeros(",
                         "det(",
                         "Zeros("],
                   "B4":["#Icon(",
                         "identity(",
                         "#Icon("],
                   "B5":"dim(",
                   "B6":"sum(",
                   "B7":"prod(",
                   "B8":"not(",
                   "B9":["nib{",
                         "iPart(",
                         "nib{"],
                   "BA":["float{",
                         "fPart(",
                         "float("],
                   "BB":{"00":"npv(",
                         "01":"irr(",
                         "02":"bal(",
                         "03":"SigmaPrn(",
                         "04":"SigmaInt(",
                         "05":[">Nom(",
                               "▶Nom(",
                               "►Nom("],
                         "06":[">Eff(",
                               "▶Eff(",
                               "►Eff("],
                         "07":"dbd(",
                         "08":"lcm(",
                         "09":"gcd(",
                         "0A":"randInt(",
                         "0B":"randBin(",
                         "0C":"sub(",
                         "0D":"stdDev",
                         "0E":"variance(",
                         "0F":["inData(",
                               "inString(",
                               "inData("],
                         "10":"normalcdf(",
                         "11":"invNorm(",
                         "12":"tcdf(",
                         "13":"chi^2cdf(",
                         "14":"Fcdf(",
                         "15":"binompdf(",
                         "16":"binomcdf(",
                         "17":"poissonpdf(",
                         "18":"poissoncdf(",
                         "19":"geometpdf(",
                         "1A":"geometcdf(",
                         "1B":"normalpdf(",
                         "1C":"tpdf(",
                         "1D":"chi^2pdf(",
                         "1E":"Fpdf(",
                         "1F":"randNorm(",
                         "20":"tvm_Pmt",
                         "21":"tvm_I%",
                         "22":"tvm_PV",
                         "23":"tvm_N",
                         "24":"tvm_FV",
                         "25":["Copy(",
                               "conj(",
                               "Copy("],
                         "26":["#Realloc",
                               "real(",
                               "Real(",
                               "#Realloc"],
                         "27":"imag(",
                         "28":"angle(",
                         "29":"cumSum(",
                         "2A":["Exch(",
                               "expr(",
                               "Exch("],
                         "2B":"length(",
                         "2C":["Data(",
                               "List(",
                               "ΔList(",
                               "Data("],
                         "2D":["Rect(",
                               "ref(",
                               "Rect("],
                         "2E":["RectI(",
                               "rref(",
                               "RectI("],
                         "2F":[">Hex",
                               ">Rect",
                               "▶Rect",
                               "►Rect",
                               "▶Hex",
                               "►Hex"],
                         "30":[">Polar",
                               "▶Polar",
                               "►Polar"],
                         "31":"[e]",
                         "32":["Freq(",
                               "SinReg",
                               "Freq("],
                         "33":"Logistic ",
                         "34":"LinRegTTest ",
                         "35":["rotC(",
                               "ShadeNorm(",
                               "rotC("],
                         "36":["rotCC(",
                               "Shade_t(",
                               "rotCC("],
                         "37":["flipV(",
                               "ShadeX2(",
                               "flipV"],
                         "38":["flipH(",
                               "ShadeF(",
                               "flipH("],
                         "39":["Matr>list(",
                               "Matr▶list(",
                               "Matr►list("],
                         "3A":["List>matr(",
                               "List▶matr(",
                               "List►matr("],
                         "3B":"Z-Test(",
                         "3C":"T-Test ",
                         "3D":"2-SampZTest(",
                         "3E":"1-PropZTest(",
                         "3F":"2-PropZTest(",
                         "40":"chi^2-Test(",
                         "41":"ZInterval",
                         "42":"2-SampZInt(",
                         "43":"1-PropZInt(",
                         "44":"2-PropZInt(",
                         "45":"GraphStyle(",
                         "46":"2-SampTTest ",
                         "47":"2-SampFTest ",
                         "48":"TInterval ",
                         "49":"2-SampTInt ",
                         "4A":"SetUpEditor ",
                         "4B":"Pmt_End",
                         "4C":"Pmt_Bgn",
                         "4D":"Real",
                         "4E":["re^thetai",
                               "re^θi"],
                         "4F":"a+bi",
                         "50":"ExprOn",
                         "51":"ExprOff",
                         "52":"ClrAllLists",
                         "53":"GetCalc(",
                         "54":"DelVar ",
                         "55":["Equ>String(",
                               "Equ▶String(",
                               "Equ►String("],
                         "56":["String>Equ(",
                               "String▶Equ(",
                               "String►Equ("],
                         "57":"Clear Entries",
                         "58":"Select(",
                         "59":"ANOVA(",
                         "5A":"ModBoxPlot",
                         "5B":"NormProbPlot",
                         "64":"G-T",
                         "65":"ZoomFit",
                         "66":"DiagnosticOn",
                         "67":"DiagnosticOff",
                         "68":"Archive ",
                         "69":"UnArchive ",
                         "6A":"Asm(",
                         "6B":["#Axiom(",
                               "AsmComp(",
                               "#Axiom("],
                         "6C":"AsmPrgm",
                         "6E":"Á",
                         "6F":"À",
                         "70":"Â",
                         "71":"Ä",
                         "72":"á",
                         "73":"à",
                         "74":"â",
                         "75":"ä",
                         "76":"É",
                         "77":"È",
                         "78":"Ê",
                         "79":"Ë",
                         "7A":"é",
                         "7B":"è",
                         "7C":"ê",
                         "7D":"ë",
                         "7F":"Ì",
                         "80":"Î",
                         "81":"Ï",
                         "82":"í",
                         "83":"ì",
                         "84":"î",
                         "85":"ï",
                         "86":"Ó",
                         "87":"Ò",
                         "88":"Ô",
                         "89":"Ö",
                         "8A":"ó",
                         "8B":"ò",
                         "8C":"ô",
                         "8D":"ö",
                         "8E":"Ú",
                         "8F":"Ù",
                         "90":"Û",
                         "91":"Ü",
                         "92":"ú",
                         "93":"ù",
                         "94":"û",
                         "95":"ü",
                         "96":"Ç",
                         "97":"ç",
                         "98":"Ñ",
                         "99":"ñ",
                         "9A":"^^'",
                         "9B":"^^`",
                         "9C":"^^:",
                         "9D":["|?",
                               "¿"],
                         "9E":["|!",
                               "¡"],
                         "9F":["alpha",
                               "α"],
                         "A0":["beta",
                               "β"],
                         "A1":["gamma",
                               "γ"],
                         "A2":["Delta",
                               "Δ"],
                         "A3":["delta",
                               "δ"],
                         "A4":["epsilon",
                               "ε"],
                         "A5":["lambda",
                               "|λ"],
                         "A6":["mu",
                               "μ"],
                         "A7":["pi",
                               "|π"],
                         "A8":["rho",
                               "ρ"],
                         "A9":["Sigma",
                               "Σ"],
                         "AB":["Phi",
                               "φ"],
                         "AC":["Omega",
                               "Ω"],
                         "AD":"phat",
                         "AE":["chi",
                               "χ"],
                         "AF":"|F",
                         "B0":"a",
                         "B1":"b",
                         "B2":"c",
                         "B3":"d",
                         "B4":"e",
                         "B5":"f",
                         "B6":"g",
                         "B7":"h",
                         "B8":"i",
                         "B9":"j",
                         "BA":"k",
                         "BC":"l",
                         "BD":"m",
                         "BE":"n",
                         "BF":"o",
                         "C0":"p",
                         "C1":"q",
                         "C2":"r",
                         "C3":"s",
                         "C4":"t",
                         "C5":"u",
                         "C6":"v",
                         "C7":"w",
                         "C8":"x",
                         "C9":"y",
                         "CA":"z",
                         "CB":"sigma",
                         "CC":"tau",
                         "CD":"Ì",
                         "CE":"GarbageCollect",
                         "CF":"|~",
                         "D1":"@",
                         "D2":"#",
                         "D3":" ",
                         "D4":"&",
                         "D5":"`",
                         "D6":";",
                         "D7":"\\",
                         "D8":"|",
                         "D9":"_",
                         "DA":"%",
                         "DB":["",
                               "▄"],
                         "DC":["|<",
                               "∠"],
                         "DD":["sharps",
                               "ß"],
                         "DE":"^^x",
                         "DF":"smallT",
                         "E0":"small0",
                         "E1":"small1",
                         "E2":"small2",
                         "E3":"small3",
                         "E4":"small4",
                         "E5":"small5",
                         "E6":"small6",
                         "E7":"small7",
                         "E8":"small8",
                         "E9":"small9",
                         "EA":"small10",
                         "EB":["<|",
                               "←",],
                         "EC":["|>",
                               "|→"],
                         "ED":["uparrow",
                               "↑"],
                         "EE":["downarrow",
                               "↓"],
                         "F0":"xmark",
                         "F1":"integral",
                         "F2":"bolduparrow",
                         "F3":"bolddownarrow",
                         "F4":"squareroot",
                         "F5":"invertedequal"},
                   "BC":["sqrt(",
                         "√("],
                   "BD":["cuberoot(",
                         "^^2sqrt(",
                         "2^^sqrt(",
                         "^^2√(",
                         "2^^√("],
                   "BE":"ln(",
                   "BF":"e^(",
                   "C0":["lambda(",
                         "Lambda(",
                         "log(",
                         "λ("],
                   "C1":"10^",
                   "C2":"sin(",
                   "C3":"sin^-1(",
                   "C4":"cos(",
                   "C5":"cos^-1(",
                   "C6":"tan(",
                   "C7":"tan^-1(",
                   "C8":"sinh(",
                   "C9":"sinh^-1(",
                   "CA":"cosh(",
                   "CB":"cosh^-1(",
                   "CC":"tanh(",
                   "CD":"tanh^-1(",
                   "CE":"If ",
                   "CF":"Then",
                   "D0":"Else",
                   "D1":"While ",
                   "D2":"Repeat ",
                   "D3":"For(",
                   "D4":"End",
                   "D5":"Return",
                   "D6":"Lbl ",
                   "D7":"Goto ",
                   "D8":"Pause ",
                   "D9":"Stop",
                   "DA":["IS>(",
                         "IS▶>(",
                         "IS►("],
                   "DB":["DS>(",
                         "DS▶(",
                         "DS►("],
                   "DC":"Input ",
                   "DD":"Prompt ",
                   "DE":"Disp ",
                   "DF":"DispGraph",
                   "E0":"Output(",
                   "E1":"ClrHome",
                   "E2":"Fill(",
                   "E3":"SortA(",
                   "E4":"SortD(",
                   "E5":"DispTable",
                   "E6":"Menu(",
                   "E7":"Send(",
                   "E8":"Get(",
                   "E9":"PlotsOn ",
                   "EA":"PlotsOff ",
                   "EB":["smallL",
                         "∟"],
                   "EC":["Pt-Mask(",
                         "Plot1(",
                         "Pt-Mask"],
                   "ED":"Plot2(",
                   "EE":"Plot3(",
                   "EF":{"00":"setDate(",
                         "01":"setTime(",
                         "02":"checkTmr(",
                         "03":"setDtFmt(",
                         "04":"setTmFmt(",
                         "05":"timeCnv(",
                         "06":"dayOfWk(",
                         "07":"getDtStr",
                         "08":"getTmStr(",
                         "09":"getDate",
                         "0A":"getTime",
                         "0B":"startTmr",
                         "0C":"getDtFmt",
                         "0D":"getTmFmt",
                         "0E":"isClockOn",
                         "0F":"ClockOff",
                         "10":"ClockOn",
                         "11":"OpenLib(",
                         "12":"ExecLib",
                         "13":"invT(",
                         "14":"chi^2GOF-Test(",
                         "15":"LinRegTInt ",
                         "16":"Manual-Fit ",
                         "17":"ZQuadrant1",
                         "18":"ZFrac1/2",
                         "19":"ZFrac1/3",
                         "1A":"ZFrac1/4",
                         "1B":"ZFrac1/5",
                         "1C":"ZFrac1/8",
                         "1D":"ZFrac1/10",
                         "1E":"mathprintbox",
                         "2E":"n/d",
                         "2F":"Un/d",
                         "30":">n/<>Un/d",
                         "31":">F<>D",
                         "32":"remainder(",
                         "33":"Sigma(",
                         "34":"logBASE(",
                         "35":"randIntNoRep(",
                         "37":"[MATHPRINT]",
                         "38":"[CLASSIC]",
                         "39":"[n/d]",
                         "3A":"[Un/d]",
                         "3B":"[AUTO]",
                         "3C":"[DEC]",
                         "3D":"[FRAC]"},
                   "F0":"^",
                   "F1":"xroot",
                   "F2":"1-Var Stats ",
                   "F3":"2-Var Stats",
                   "F4":"LinReg(a+bx) ",
                   "F5":"ExpReg ",
                   "F6":["LnReg ",
                         "LnReg",
                         "LnReg "],
                   "F7":"PwrReg ",
                   "F8":"Med-Med ",
                   "F9":"QuadReg ",
                   "FA":"ClrList ",
                   "FB":["Port",
                         "ClrTable",
                         "Port"],
                   "FC":"Histogram",
                   "FD":"xyLine",
                   "FE":"Scatter",
                   "FF":"LinReg(ax+b) "}


        (self.inverted_dict, self.max_word_size) = _flip_dictionary(self.dictionary)

        _register_new(self.inverted_dict, '"', 'appv')
        _register_new(self.inverted_dict, '"', 'var')
        _register_new(self.inverted_dict, '"', 'grp')
        _register_new(self.inverted_dict, '"', 'prgm')

        _register_new(self.inverted_dict, '[', 'Pic0')
        _register_new(self.inverted_dict, '[', 'Pic1')
        _register_new(self.inverted_dict, '[', 'Pic2')
        _register_new(self.inverted_dict, '[', 'Pic3')
        _register_new(self.inverted_dict, '[', 'Pic4')
        _register_new(self.inverted_dict, '[', 'Pic5')
        _register_new(self.inverted_dict, '[', 'Pic6')
        _register_new(self.inverted_dict, '[', 'Pic7')
        _register_new(self.inverted_dict, '[', 'Pic8')
        _register_new(self.inverted_dict, '[', 'Pic9')

        # Adding shortcuts (hand-coded)
        self.shortcuts = {"^^r^^r" : "^^rr",
                          "[e][e]" : "[ee]"}

        self.inverted_dict["^^rr"] = self.inverted_dict["^^r"] + self.inverted_dict["^^r"]
        self.inverted_dict["[ee]"] = self.inverted_dict["[e]"] + self.inverted_dict["[e]"]
        return


class Basic():
    ####
    #### NOTE:
    #### I could have eliminated much redundancy by merging Axe() and Basic(),
    #### but I decided to leave them seperated in case Axe evolves further
    #### and further away from TI-Basic.
    ####
    def __init__(self):
        # The list indicates how much to increment (or decrement) the current
        # line, next line, and 3rd line away.
        self.specials = {"CE":[0,1,0],       # If
                         "CF":[0,1,1],       # Then
                         "D1":[0,1,1],       # While
                         "D2":[0,1,1],       # For
                         "D3":[0,1,1],       # Repeat
                         "DA":[0,1,1],       # IS>(
                         "DB":[0,1,1],       # DS>(
                         "D4":[-1,-1,-1],    # End
                         "D0":[-1,0,0]}      # Else

        # If True, indentation is added immediately.
        self.end = {"3F":True,     # \n (newline)
                    "3E":False}    # :  (colon)
        
        self.singles = {'"'      : ['"', "->", "→", '\n'],
                        '['      : [']', "->", "→", '\n'],
                        '{'      : ['}', "->", "→", '\n'],}
        
        ### VERY IMPORTANT NOTE:
        ### All redundancy in the below dictionary is deliberate.
        ### The first item in any list is the output for ascii character mode.
        ### The last item in any list is the output for special characters mode.
        ### Any items in the middle are alternate token forms.
        ###
        ### If there is no special character forms for a token, but there are alternate
        ### forms, the first and last items should be the same.

        self.dictionary = {"00":"",
                   "01":[">DMS",
                         ">Tok",
                         "▶Tok",
                         "►Tok",
                         "▶DMS",
                         "►DMS,"],
                   "02":[">Dec",
                         "▶Dec",
                         "►Dec"],
                   "03":[">Frac",
                         ">Char",
                         "▶Char",
                         "►Char",
                         "▶Frac",
                         "►Frac"],
                   "04":["->",
                         "→"],
                   "05":"Boxplot",
                   "06":"[",
                   "07":"]",
                   "08":"{",
                   "09":"}",
                   "0A":"^^r",
                   "0B":["^^o",
                         "°"],
                   "0C":"^^-1",
                   "0D":"^^2",
                   "0E":["T^^",
                         "^^T",
                         "T^^"],
                   "0F":"^^3",
                   "10":"(",
                   "11":")",
                   "12":"round(",
                   "13":"pxl-Test(",
                   "14":"augment(",
                   "15":"rowSwap(",
                   "16":"row+(",
                   "17":"*row(",
                   "18":"*row+(",
                   "19":"max(",
                   "1A":"min(",
                   "1B":["R>Pr(",
                         "R▶Pr(",
                         "R►Pr("],
                   "1C":["R>Ptheta(",
                         "R▶Pθ(",
                         "R►Pθ("],
                   "1D":["P>Rx(",
                         "P▶Rx(",
                         "P►Rx("],
                   "1E":["P>Ry(",
                         "P▶Ry(",
                         "P►Ry("],
                   "1F":"median(",
                   "20":"randM(",
                   "21":"mean(",
                   "22":"solve(",
                   "23":"seq(",
                   "24":"fnInt(",
                   "25":"nDeriv(",
                   "27":"fMin(",
                   "28":"fMax(",
                   "29":" ",
                   "2A":"\"",
                   "2B":",",
                   "2C":"[i]",
                   "2D":"!",
                   "2E":"CubicReg ",
                   "2F":"QuartReg ",
                   "30":"0",
                   "31":"1",
                   "32":"2",
                   "33":"3",
                   "34":"4",
                   "35":"5",
                   "36":"6",
                   "37":"7",
                   "38":"8",
                   "39":"9",
                   "3A":".",
                   "3B":"|E",
                   "3C":" or ",
                   "3D":" xor ",
                   "3E":":",
                   "3F":"\n",
                   "40":" and ",
                   "41":"A",
                   "42":"B",
                   "43":"C",
                   "44":"D",
                   "45":"E",
                   "46":"F",
                   "47":"G",
                   "48":"H",
                   "49":"I",
                   "4A":"J",
                   "4B":"K",
                   "4C":"L",
                   "4D":"M",
                   "4E":"N",
                   "4F":"O",
                   "50":"P",
                   "51":"Q",
                   "52":"R",
                   "53":"S",
                   "54":"T",
                   "55":"U",
                   "56":"V",
                   "57":"W",
                   "58":"X",
                   "59":"Y",
                   "5A":"Z",
                   "5B":["theta",
                         "θ"],
                   "5C":{"00":"[A]",
                         "01":"[B]",
                         "02":"[C]",
                         "03":"[D]",
                         "04":"[E]",
                         "05":"[F]",
                         "06":"[G]",
                         "07":"[H]",
                         "08":"[I]",
                         "09":"[J]"},
                   "5D":{"00":"L1",
                         "01":"L2",
                         "02":"L3",
                         "03":"L4",
                         "04":"L5",
                         "05":"L6"},
                   "5E":{"10":"Y1",
                         "11":"Y2",
                         "12":"Y3",
                         "13":"Y4",
                         "14":"Y5",
                         "15":"Y6",
                         "16":"Y7",
                         "17":"Y8",
                         "18":"Y9",
                         "19":"Y0",
                         "20":"X1T",
                         "21":"Y1T",
                         "22":"X2T",
                         "23":"Y2T",
                         "24":"X3T",
                         "25":"Y3T",
                         "26":"X4T",
                         "27":"Y4T",
                         "28":"X5T",
                         "29":"Y5T",
                         "2A":"X6T",
                         "2B":"Y6T",
                         "40":"r1",
                         "41":"r2",
                         "42":"r3",
                         "43":"r4",
                         "44":"r5",
                         "45":"r6",
                         "80":"var",
                         "81":"appv",
                         "82":"grp"},
                   "5F":"prgm",
                   "60":{"00":"Pic1",
                         "01":"Pic2",
                         "02":"Pic3",
                         "03":"Pic4",
                         "04":"Pic5",
                         "05":"Pic6",
                         "06":"Pic7",
                         "07":"Pic8",
                         "08":"Pic9",
                         "09":"Pic0"},
                   "61":{"00":"GDB1",
                         "01":"GDB2",
                         "02":"GDB3",
                         "03":"GDB4",
                         "04":"GDB5",
                         "05":"GDB6",
                         "06":"GDB7",
                         "07":"GDB8",
                         "08":"GDB9",
                         "09":"GDB0"},
                   "62":{"01":"[RegEQ]",
                         "02":"[n]",
                         "03":"[xhat]",
                         "04":"[Sigmax]",
                         "05":"[Sigmax^2]",
                         "06":"[Sx]",
                         "07":"[sigmax]",
                         "08":"[minX]",
                         "09":"[maxX]",
                         "0A":"[minY]",
                         "0B":"[maxY]",
                         "0C":"[yhat]",
                         "0D":"[Sigmay]",
                         "0E":"[Sigmay^2]",
                         "0F":"[Sy]",
                         "10":"[sigmay]",
                         "11":"[Sigmaxy]",
                         "12":"[r]",
                         "13":"[Med]",
                         "14":"[Q1]",
                         "15":"[Q3]",
                         "16":"[a]",
                         "17":"[b]",
                         "18":"[c]",
                         "19":"[d]",
                         "1A":"[e]",
                         "1B":"[x1]",
                         "1C":"[x2]",
                         "1D":"[x3]",
                         "1E":"[y1]",
                         "1F":"[y2]",
                         "20":"[y3]",
                         "21":"[recursiven]",
                         "22":"[p]",
                         "23":"[z]",
                         "24":"[t]",
                         "25":"[chi^2]",
                         "26":"|F",
                         "27":"[df]",
                         "28":"[phat]",
                         "29":"[phat1]",
                         "2A":"[phat2]",
                         "2B":"[xhat1]",
                         "2C":"[Sx1]",
                         "2D":"[n1]",
                         "2E":"[xhat2]",
                         "2F":"[Sx2]",
                         "30":"[n2]",
                         "31":"[Sxp]",
                         "32":"[lower]",
                         "33":"[upper]",
                         "34":"[s]",
                         "35":"[r^2]",
                         "36":"[R^2]",
                         "37":"[factordf]",
                         "38":"[factorSS]",
                         "39":"[factorMS]",
                         "3A":"[errordf]",
                         "3B":"[errorSS]",
                         "3C":"[errorMS]"},
                   "63":{"00":"ZXscl",
                         "01":"ZYscl",
                         "02":"Xscl",
                         "03":"Yscl",
                         "04":"u(nMin)",
                         "05":"v(nMin)",
                         "06":"Un-1",
                         "07":"Vn-1",
                         "08":"Zu(nmin)",
                         "09":"Zv(nmin)",
                         "0A":"Xmin",
                         "0B":"Xmax",
                         "0C":"Ymin",
                         "0D":"Ymax",
                         "0E":"Tmin",
                         "0F":"Tmax",
                         "10":["thetaMin",
                               "θMin"],
                         "11":["thetaMax",
                               "θMax"],
                         "12":"ZXmin",
                         "13":"ZXmax",
                         "14":"ZYmin",
                         "15":"ZYmax",
                         "16":["Zthetamin",
                               "ZθMin"],
                         "17":["Zthetamax",
                               "Zθmax"],
                         "18":"ZTmin",
                         "19":"ZTmax",
                         "1A":"TblStart",
                         "1B":"PlotStart",
                         "1C":"ZPlotStart",
                         "1D":"nMax",
                         "1E":"ZnMax",
                         "1F":"nMin",
                         "20":"ZnMin",
                         "21":"DeltaTbl",
                         "22":"Tstep",
                         "23":["thetastep",
                               "θstep"],
                         "24":"ZTstep",
                         "25":["Zthetastep",
                               "Zθstep"],
                         
                         "26":"DeltaX",
                         "27":"DeltaY",
                         "28":"XFact",
                         "29":"YFact",
                         "2A":"TblInput",
                         "2B":"|N",
                         "2C":"I%",
                         "2D":"PV",
                         "2E":"PMT",
                         "2F":"FV",
                         "30":"P/Y",
                         "31":"C/Y",
                         "32":"w(nMin)",
                         "33":"Zw(nMin)",
                         "34":"PlotStep",
                         "35":"ZPlotStep",
                         "36":"Xres",
                         "37":"ZXres"},
                   "64":"Radian",
                   "65":"Degree",
                   "66":"Normal",
                   "67":"Sci",
                   "68":"Eng",
                   "69":"Float",
                   "6A":"=",
                   "6B":"<",
                   "6C":">",
                   "6D":["<=",
                         "=<",
                         "≤"],
                   "6E":["=>",
                         ">=",
                         "≥"],
                   "6F":["!=",
                         "=!",
                         "=/=",
                         "≠"],
                   "70":"+",
                   "71":"-",
                   "72":"Ans",
                   "73":"Fix ",
                   "74":"Horiz",
                   "75":"Full",
                   "76":"Func",
                   "77":"Param",
                   "78":"Polar",
                   "79":"Seq",
                   "7A":"IndpntAuto",
                   "7B":"IndpntAsk",
                   "7C":"DependAuto",
                   "7D":"DependAsk",
                   "7E":{"00":"Sequential",
                         "01":"Simul",
                         "02":"PolarGC",
                         "03":"RectGC",
                         "04":"CoordOn",
                         "05":"CoordOff",
                         "06":"Connected",
                         "07":"Dot",
                         "08":"AxesOn",
                         "09":"AxesOff",
                         "0A":"GridOn",
                         "0B":"GridOff",
                         "0C":"LabelOn",
                         "0D":"LabelOff",
                         "0E":"Web",
                         "0F":"Time",
                         "10":"uvAxes",
                         "11":"vwAxes",
                         "12":"uwAxes"},
                   "7F":[" plotsquare ",
                         "plotsquare"],    # □
                   "80":[" plotcross ",
                         "plotcross",
                         "|+"],
                   "81":[" plotdot ",
                         "plotdot",
                         " plotdot "],
                   "82":"*",
                   "83":["/",
                         "÷",
                         "/"],
                   "84":"Trace",
                   "85":"ClrDraw",
                   "86":"ZStandard",
                   "87":"ZTrig",
                   "88":"ZBox",
                   "89":"Zoom In",
                   "8A":"Zoom Out",
                   "8B":"ZSquare",
                   "8C":"ZInteger",
                   "8D":"ZPrevious",
                   "8E":"ZDecimal",
                   "8F":"ZoomStat",
                   "90":"ZoomRcl",
                   "91":"PrintScreen",
                   "92":"ZoomSto",
                   "93":"Text(",
                   "94":" nPr ",
                   "95":" nCr ",
                   "96":["FnOn ",
                         "FnOn",
                         "FnOn "],
                   "97":["FnOff ",
                         "FnOff",
                         "FnOff "],
                   "98":["StorePic ",
                         "StorePic",
                         "StorePic "],
                   "99":["RecallPic ",
                         "RecallPic",
                         "RecallPic "],
                   "9A":["StoreGDB ",
                         "StoreGDB",
                         "StoreGDB "],
                   "9B":["RecallGDB ",
                         "RecallGDB",
                         "RecallGDB "],
                   "9C":"Line(",
                   "9D":"Vertical ",
                   "9E":"Pt-On(",
                   "9F":"Pt-Off(",
                   "A0":"Pt-Change(",
                   "A1":"Pxl-On(",
                   "A2":"Pxl-Off(",
                   "A3":"Pxl-Change(",
                   "A4":"Shade(",
                   "A5":"Circle(",
                   "A6":"Horizontal ",
                   "A7":"Tangent(",
                   "A8":["DrawInv ",
                         "DrawInv",
                         "DrawInv "],
                   "A9":"Text ",
                   "AA":{"00":"Str1",
                         "01":"Str2",
                         "02":"Str3",
                         "03":"Str4",
                         "04":"Str5",
                         "05":"Str6",
                         "06":"Str7",
                         "07":"Str8",
                         "08":"Str9",
                         "09":"Str0"},
                   "AB":"rand",
                   "AC":["pi",
                         "π"],
                   "AD":"getKey",
                   "AE":"'",
                   "AF":"?",
                   "B0":"~",
                   "B1":["int(",
                         "sign{",
                         "int("],
                   "B2":"abs(",
                   "B3":["det(",
                         "Zeros(",
                         "det("],
                   "B4":["identity(",
                         "#Icon(",
                         "identity("],
                   "B5":"dim(",
                   "B6":"sum(",
                   "B7":"prod(",
                   "B8":"not(",
                   "B9":["iPart(",
                         "nib{",
                         "iPart("],
                   "BA":["fPart(",
                         "float{",
                         "fPart("],
                   "BB":{"00":"npv(",
                         "01":"irr(",
                         "02":"bal(",
                         "03":"SigmaPrn(",
                         "04":"SigmaInt(",
                         "05":[">Nom(",
                               "▶Nom(",
                               "►Nom("],
                         "06":[">Eff(",
                               "▶Eff(",
                               "►Eff("],
                         "07":"dbd(",
                         "08":"lcm(",
                         "09":"gcd(",
                         "0A":"randInt(",
                         "0B":"randBin(",
                         "0C":"sub(",
                         "0D":"stdDev",
                         "0E":"variance(",
                         "0F":["inString(",
                               "inString(",
                               "inData("],
                         "10":"normalcdf(",
                         "11":"invNorm(",
                         "12":"tcdf(",
                         "13":"chi^2cdf(",
                         "14":"Fcdf(",
                         "15":"binompdf(",
                         "16":"binomcdf(",
                         "17":"poissonpdf(",
                         "18":"poissoncdf(",
                         "19":"geometpdf(",
                         "1A":"geometcdf(",
                         "1B":"normalpdf(",
                         "1C":"tpdf(",
                         "1D":"chi^2pdf(",
                         "1E":"Fpdf(",
                         "1F":"randNorm(",
                         "20":"tvm_Pmt",
                         "21":"tvm_I%",
                         "22":"tvm_PV",
                         "23":"tvm_N",
                         "24":"tvm_FV",
                         "25":["conj(",
                               "Copy(",
                               "conj("],
                         "26":["real(",
                               "#Realloc",
                               "Real(",
                               "real("],
                         "27":"imag(",
                         "28":"angle(",
                         "29":"cumSum(",
                         "2A":["expr(",
                               "Exch(",
                               "expr("],
                         "2B":"length(",
                         "2C":["List(",
                               "Data(",
                               "ΔList("],
                         "2D":["ref(",
                               "Rect(",
                               "ref("],
                         "2E":["rref(",
                               "RectI(",
                               "rref("],
                         "2F":[">Rect",
                               ">Hex",
                               "▶Hex",
                               "►Hex",
                               "▶Rect",
                               "►Rect"],
                         "30":[">Polar",
                               "▶Polar",
                               "►Polar"],
                         "31":"[e]",
                         "32":["SinReg",
                               "Freq(",
                               "SinReg"],
                         "33":"Logistic ",
                         "34":"LinRegTTest ",
                         "35":["ShadeNorm(",
                               "rotC(",
                               "ShadeNorm("],
                         "36":["Shade_t(",
                               "rotCC(",
                               "Shade_t("],
                         "37":["ShadeX2(",
                               "flipV(",
                               "ShadeX2("],
                         "38":["ShadeF(",
                               "flipH(",
                               "ShadeF("],
                         "39":["Matr>list(",
                               "Matr▶list(",
                               "Matr►list("],
                         "3A":["List>matr(",
                               "List▶matr(",
                               "List►matr("],
                         "3B":"Z-Test(",
                         "3C":"T-Test ",
                         "3D":"2-SampZTest(",
                         "3E":"1-PropZTest(",
                         "3F":"2-PropZTest(",
                         "40":"chi^2-Test(",
                         "41":"ZInterval",
                         "42":"2-SampZInt(",
                         "43":"1-PropZInt(",
                         "44":"2-PropZInt(",
                         "45":"GraphStyle(",
                         "46":"2-SampTTest ",
                         "47":"2-SampFTest ",
                         "48":"TInterval ",
                         "49":"2-SampTInt ",
                         "4A":"SetUpEditor ",
                         "4B":"Pmt_End",
                         "4C":"Pmt_Bgn",
                         "4D":"Real",
                         "4E":["re^thetai",
                               "re^θi"],
                         "4F":"a+bi",
                         "50":"ExprOn",
                         "51":"ExprOff",
                         "52":"ClrAllLists",
                         "53":"GetCalc(",
                         "54":"DelVar ",
                         "55":["Equ>String(",
                               "Equ▶String(",
                               "Equ►String("],
                         "56":["String>Equ(",
                               "String▶Equ(",
                               "String►Equ("],
                         "57":"Clear Entries",
                         "58":"Select(",
                         "59":"ANOVA(",
                         "5A":"ModBoxPlot",
                         "5B":"NormProbPlot",
                         "64":"G-T",
                         "65":"ZoomFit",
                         "66":"DiagnosticOn",
                         "67":"DiagnosticOff",
                         "68":"Archive ",
                         "69":"UnArchive ",
                         "6A":"Asm(",
                         "6B":["AsmComp(",
                               "#Axiom",
                               "AxmComp("],
                         "6C":"AsmPrgm",
                         "6E":"Á",
                         "6F":"À",
                         "70":"Â",
                         "71":"Ä",
                         "72":"á",
                         "73":"à",
                         "74":"â",
                         "75":"ä",
                         "76":"É",
                         "77":"È",
                         "78":"Ê",
                         "79":"Ë",
                         "7A":"é",
                         "7B":"è",
                         "7C":"ê",
                         "7D":"ë",
                         "7F":"Ì",
                         "80":"Î",
                         "81":"Ï",
                         "82":"í",
                         "83":"ì",
                         "84":"î",
                         "85":"ï",
                         "86":"Ó",
                         "87":"Ò",
                         "88":"Ô",
                         "89":"Ö",
                         "8A":"ó",
                         "8B":"ò",
                         "8C":"ô",
                         "8D":"ö",
                         "8E":"Ú",
                         "8F":"Ù",
                         "90":"Û",
                         "91":"Ü",
                         "92":"ú",
                         "93":"ù",
                         "94":"û",
                         "95":"ü",
                         "96":"Ç",
                         "97":"ç",
                         "98":"Ñ",
                         "99":"ñ",
                         "9A":"^^'",
                         "9B":"^^`",
                         "9C":"^^:",
                         "9D":["|?",
                               "¿"],
                         "9E":["|!",
                               "¡"],
                         "9F":["alpha",
                               "α"],
                         "A0":["beta",
                               "β"],
                         "A1":["gamma",
                               "γ"],
                         "A2":["Delta",
                               "Δ"],
                         "A3":["delta",
                               "δ"],
                         "A4":["epsilon",
                               "ε"],
                         "A5":["lambda",
                               "|λ"],
                         "A6":["mu",
                               "μ"],
                         "A7":["pi",
                               "|π"],
                         "A8":["rho",
                               "ρ"],
                         "A9":["Sigma",
                               "Σ"],
                         "AB":["Phi",
                               "φ"],
                         "AC":["Omega",
                               "Ω"],
                         "AD":"phat",
                         "AE":["chi",
                               "χ"],
                         "AF":"|F",
                         "B0":"a",
                         "B1":"b",
                         "B2":"c",
                         "B3":"d",
                         "B4":"e",
                         "B5":"f",
                         "B6":"g",
                         "B7":"h",
                         "B8":"i",
                         "B9":"j",
                         "BA":"k",
                         "BC":"l",
                         "BD":"m",
                         "BE":"n",
                         "BF":"o",
                         "C0":"p",
                         "C1":"q",
                         "C2":"r",
                         "C3":"s",
                         "C4":"t",
                         "C5":"u",
                         "C6":"v",
                         "C7":"w",
                         "C8":"x",
                         "C9":"y",
                         "CA":"z",
                         "CB":"sigma",
                         "CC":"tau",
                         "CD":"Ì",
                         "CE":"GarbageCollect",
                         "CF":"|~",
                         "D1":"@",
                         "D2":"#",
                         "D3":" ",
                         "D4":"&",
                         "D5":"`",
                         "D6":";",
                         "D7":"\\",
                         "D8":"|",
                         "D9":"_",
                         "DA":"%",
                         "DB":["",
                               "▄"],
                         "DC":["|<",
                               "∠"],
                         "DD":["sharps",
                               "ß"],
                         "DE":"^^x",
                         "DF":"smallT",
                         "E0":"small0",
                         "E1":"small1",
                         "E2":"small2",
                         "E3":"small3",
                         "E4":"small4",
                         "E5":"small5",
                         "E6":"small6",
                         "E7":"small7",
                         "E8":"small8",
                         "E9":"small9",
                         "EA":"small10",
                         "EB":["<|",
                               "←",],
                         "EC":["|>",
                               "|→"],
                         "ED":["uparrow",
                               "↑"],
                         "EE":["downarrow",
                               "↓"],
                         "F0":"xmark",
                         "F1":"integral",
                         "F2":"bolduparrow",
                         "F3":"bolddownarrow",
                         "F4":"squareroot",
                         "F5":"invertedequal"},
                   "BC":["sqrt(",
                         "√("],
                   "BD":["cuberoot(",
                         "^^2sqrt(",
                         "2^^sqrt(",
                         "^^2√(",
                         "2^^√("],
                   "BE":"ln(",
                   "BF":"e^(",
                   "C0":["log(",
                         "lambda(",
                         "Lambda(",
                         "λ(",
                         "log("],
                   "C1":"10^",
                   "C2":"sin(",
                   "C3":"sin^-1(",
                   "C4":"cos(",
                   "C5":"cos^-1(",
                   "C6":"tan(",
                   "C7":"tan^-1(",
                   "C8":"sinh(",
                   "C9":"sinh^-1(",
                   "CA":"cosh(",
                   "CB":"cosh^-1(",
                   "CC":"tanh(",
                   "CD":"tanh^-1(",
                   "CE":"If ",
                   "CF":"Then",
                   "D0":"Else",
                   "D1":"While ",
                   "D2":"Repeat ",
                   "D3":"For(",
                   "D4":"End",
                   "D5":"Return",
                   "D6":"Lbl ",
                   "D7":"Goto ",
                   "D8":"Pause ",
                   "D9":"Stop",
                   "DA":["IS>(",
                         "IS▶>(",
                         "IS►("],
                   "DB":["DS>(",
                         "DS▶(",
                         "DS►("],
                   "DC":"Input ",
                   "DD":"Prompt ",
                   "DE":"Disp ",
                   "DF":"DispGraph",
                   "E0":"Output(",
                   "E1":"ClrHome",
                   "E2":"Fill(",
                   "E3":"SortA(",
                   "E4":"SortD(",
                   "E5":"DispTable",
                   "E6":"Menu(",
                   "E7":"Send(",
                   "E8":"Get(",
                   "E9":"PlotsOn ",
                   "EA":"PlotsOff ",
                   "EB":["smallL",
                         "∟"],
                   "EC":["Plot1(",
                         "Pt-Mask(",
                         "Plot1("],
                   "ED":"Plot2(",
                   "EE":"Plot3(",
                   "EF":{"00":"setDate(",
                         "01":"setTime(",
                         "02":"checkTmr(",
                         "03":"setDtFmt(",
                         "04":"setTmFmt(",
                         "05":"timeCnv(",
                         "06":"dayOfWk(",
                         "07":"getDtStr",
                         "08":"getTmStr(",
                         "09":"getDate",
                         "0A":"getTime",
                         "0B":"startTmr",
                         "0C":"getDtFmt",
                         "0D":"getTmFmt",
                         "0E":"isClockOn",
                         "0F":"ClockOff",
                         "10":"ClockOn",
                         "11":"OpenLib(",
                         "12":"ExecLib",
                         "13":"invT(",
                         "14":"chi^2GOF-Test(",
                         "15":"LinRegTInt ",
                         "16":"Manual-Fit ",
                         "17":"ZQuadrant1",
                         "18":"ZFrac1/2",
                         "19":"ZFrac1/3",
                         "1A":"ZFrac1/4",
                         "1B":"ZFrac1/5",
                         "1C":"ZFrac1/8",
                         "1D":"ZFrac1/10",
                         "1E":"mathprintbox",
                         "2E":"n/d",
                         "2F":"Un/d",
                         "30":">n/<>Un/d",
                         "31":">F<>D",
                         "32":"remainder(",
                         "33":"Sigma(",
                         "34":"logBASE(",
                         "35":"randIntNoRep(",
                         "37":"[MATHPRINT]",
                         "38":"[CLASSIC]",
                         "39":"[n/d]",
                         "3A":"[Un/d]",
                         "3B":"[AUTO]",
                         "3C":"[DEC]",
                         "3D":"[FRAC]"},
                   "F0":"^",
                   "F1":"xroot",
                   "F2":"1-Var Stats ",
                   "F3":"2-Var Stats",
                   "F4":"LinReg(a+bx) ",
                   "F5":"ExpReg ",
                   "F6":["LnReg ",
                         "LnReg",
                         "LnReg "],
                   "F7":"PwrReg ",
                   "F8":"Med-Med ",
                   "F9":"QuadReg ",
                   "FA":"ClrList ",
                   "FB":["ClrTable",
                         "Port",
                         "ClrTable"],
                   "FC":"Histogram",
                   "FD":"xyLine",
                   "FE":"Scatter",
                   "FF":"LinReg(ax+b) "}


        (self.inverted_dict, self.max_word_size) = _flip_dictionary(self.dictionary)

        # Adding shortcuts (hand-coded)
        self.shortcuts = {"^^r^^r" : "^^rr",
                          "[e][e]" : "[ee]"}

        self.inverted_dict["^^rr"] = self.inverted_dict["^^r"] + self.inverted_dict["^^r"]
        self.inverted_dict["[ee]"] = self.inverted_dict["[e]"] + self.inverted_dict["[e]"]
        return

tokens_type ={"axe":Axe(),
              "basic":Basic()}


